home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ULARN.ARJ / ULARN.TAR / ularn / create.c < prev    next >
C/C++ Source or Header  |  1989-10-25  |  15KB  |  695 lines

  1. /*    create.c        */
  2. #include "header.h"
  3.  
  4. extern char spelknow[],larnlevels[];
  5. extern char beenhere[],wizard,level;
  6. extern short oldx,oldy;
  7.  
  8. /*
  9.     makeplayer()
  10.  
  11.     subroutine to create the player and the players attributes
  12.     this is called at the beginning of a game and at no other time
  13.  */
  14. makeplayer()
  15. {
  16.     register int i;
  17.     extern int char_picked;
  18.  
  19.     scbr();  
  20.     clear();
  21.     c[LEVEL]=1;        /*    player starts at level one    */
  22.     c[REGENCOUNTER]=16;
  23.     c[ECOUNTER]=96;        /*start regeneration correctly*/
  24.  
  25.     c[SHIELD] = c[WEAR] = c[WIELD] = -1;
  26.  
  27.     if (char_picked >= 'a' && char_picked <= 'h') 
  28.         pick_char(char_picked);
  29.     else {
  30.         for (i=0; i<26; i++)  
  31.             iven[i]=0;
  32.         pick_char(0);
  33.     }
  34.     playerx=rnd(MAXX-2);    
  35.     playery=rnd(MAXY-2);
  36.     oldx=0;            
  37.     oldy=25;
  38.     gtime=0;    /*    time clock starts at zero    */
  39.     cbak[SPELLS] = -50;
  40.     recalc();
  41. }
  42.  
  43. /*
  44.     newcavelevel(level)
  45.     int level;
  46.  
  47.     function to enter a new level.  This routine must be called anytime the
  48.     player changes levels.  If that level is unknown it will be created.
  49.     A new set of monsters will be created for a new level, and existing
  50.     levels will get a few more monsters.
  51.     Note that it is here we remove genocided monsters from the present level
  52.  */
  53. newcavelevel(x)
  54. register int x;
  55. {
  56.     register int i,j;
  57.  
  58.     if (beenhere[level]) 
  59.         savelevel();    /* put the level back into storage    */
  60.     level = x;    /* get the new level and put in working storage*/
  61.     if (beenhere[x]==0) 
  62.         for (i=0; i<MAXY; i++) 
  63.             for (j=0; j<MAXX; j++) 
  64.                 know[j][i]=mitem[j][i]=0;
  65.     else {     
  66.         getlevel(); 
  67.         sethp(0);  
  68.         goto chgn;  /* yuck! */
  69.     }
  70.     makemaze(x);    
  71.     makeobject(x);    
  72.     beenhere[x]=1;  
  73.     sethp(1);
  74.  
  75. #if WIZID
  76.     if (wizard || x==0)
  77. #else
  78.         if (x==0)
  79. #endif
  80.             for (j=0; j<MAXY; j++)
  81.                 for (i=0; i<MAXX; i++)
  82.                     know[i][j]=1;
  83. chgn:     
  84.     checkgen();    /* wipe out any genocided monsters */
  85. }
  86.  
  87. /*
  88.     makemaze(level)
  89.     int level;
  90.  
  91.     subroutine to make the caverns for a given level.  only walls are made.
  92.  */
  93. static int mx,mxl,mxh,my,myl,myh,tmp2;
  94. makemaze(k)
  95. int k;
  96. {
  97.     register int i,j;
  98.     int tmp, z;
  99.  
  100.     if (k > 1 && (rnd(17)<=4 || k==MAXLEVEL-1 || k==MAXLEVEL+MAXVLEVEL-1)) {
  101.         if (cannedlevel(k));    
  102.         return;        /* read maze from data file */
  103.     }
  104.     if (k==0)  
  105.         tmp=0;  
  106.     else 
  107.         tmp=OWALL;
  108.     for (i=0; i<MAXY; i++)    
  109.         for (j=0; j<MAXX; j++)    
  110.             item[j][i]=tmp;
  111.     if (k==0) 
  112.         return;        
  113.     eat(1,1);
  114.     if (k==1) 
  115.         item[33][MAXY-1]=0;    /* exit from dungeon */
  116.  
  117.     /*    now for open spaces -- not on level 10    */
  118.     if (k != MAXLEVEL-1) {
  119.         tmp2 = rnd(3)+3;
  120.         for (tmp=0; tmp<tmp2; tmp++) {     
  121.             my = rnd(11)+2;   
  122.             myl = my - rnd(2);  
  123.             myh = my + rnd(2);
  124.             if (k < MAXLEVEL) {     
  125.                 mx = rnd(44)+5;  
  126.                 mxl = mx - rnd(4);  
  127.                 mxh = mx + rnd(12)+3;
  128.                 z=0;
  129.             }
  130.             else {     
  131.                 mx = rnd(60)+3;  
  132.                 mxl = mx - rnd(2);  
  133.                 mxh = mx + rnd(2);
  134.                 z = makemonst(k);
  135.             }
  136.             for (i=mxl; i<mxh; i++)        
  137.                 for (j=myl; j<myh; j++) {      
  138.                     item[i][j]=0;
  139.                     if ((mitem[i][j]=z)) 
  140.                         hitp[i][j]=monster[z].hitpoints;
  141.                 }
  142.         }
  143.     }
  144.     if (k!=MAXLEVEL-1) {     
  145.         my=rnd(MAXY-2);  
  146.         for (i=1; i<MAXX-1; i++)    
  147.             item[i][my] = 0; 
  148.     }
  149.     if (k>1)  treasureroom(k);
  150. }
  151.  
  152. /*
  153.     function to eat away a filled in maze
  154.  */
  155. eat(xx,yy)
  156. register int xx,yy;
  157. {
  158.     register int dir,try;
  159.  
  160.     dir = rnd(4);    
  161.     try=2;
  162.     while (try) {
  163.         switch(dir) {
  164.         case 1:    
  165.             if (xx <= 2) break;    /*    west    */
  166.             if ((item[xx-1][yy]!=OWALL) || (item[xx-2][yy]!=OWALL))    
  167.                 break;
  168.             item[xx-1][yy] = item[xx-2][yy] = 0;
  169.             eat(xx-2,yy);    
  170.             break;
  171.         case 2:    
  172.             if (xx >= MAXX-3) break;  /*    east    */
  173.             if ((item[xx+1][yy]!=OWALL) || (item[xx+2][yy]!=OWALL))    
  174.                 break;
  175.             item[xx+1][yy] = item[xx+2][yy] = 0;
  176.             eat(xx+2,yy);    
  177.             break;
  178.         case 3:    
  179.             if (yy <= 2) break;    /*    south    */
  180.             if ((item[xx][yy-1]!=OWALL) || (item[xx][yy-2]!=OWALL))    
  181.                 break;
  182.             item[xx][yy-1] = item[xx][yy-2] = 0;
  183.             eat(xx,yy-2);    
  184.             break;
  185.         case 4:    
  186.             if (yy >= MAXY-3 ) break;    /*north    */
  187.             if ((item[xx][yy+1]!=OWALL) || (item[xx][yy+2]!=OWALL))    
  188.                 break;
  189.             item[xx][yy+1] = item[xx][yy+2] = 0;
  190.             eat(xx,yy+2);    
  191.             break;
  192.         };
  193.         if (++dir > 4)    {     
  194.             dir=1;  
  195.             --try; 
  196.         }
  197.     }
  198. }
  199.  
  200. /*
  201.  *    function to read in a maze from a data file
  202.  *
  203.  *    Format of maze data file:  
  204.  *                1st character = # of mazes in file (ascii digit)
  205.  *                For each maze: 
  206.  *                    18 lines (1st 17 used) 
  207.  *                    67 characters per line
  208.  *
  209.  *    Special characters in maze data file:
  210.  *
  211.  *        #    wall            D    door
  212.  *        .    random monster        ~    eye of larn
  213.  *        !    cure dianthroritis    -    random object
  214.  */
  215. cannedlevel(k)
  216. int k;
  217. {
  218.     char *row,*lgetl();
  219.     register int i,j;
  220.     int it,arg,mit,marg;
  221.  
  222.     if (lopen(larnlevels)<0) {
  223.         write(1,"Can't open the maze data file\n",30);     
  224.         died(-282); 
  225.         return(0);
  226.     }
  227.     for (i=18*rund(20); i>0; i--)    
  228.         lgetl();   /* advance to desired maze */
  229.  
  230.     for (i=0; i<MAXY; i++) {
  231.         row = lgetl();
  232.         for (j=0; j<MAXX; j++) {
  233.             it = mit = arg = marg = 0;
  234.             switch(*row++) {
  235.             case '#':     
  236.                 it = OWALL;    
  237.                 break;
  238.             case 'D':     
  239.                 it = OCLOSEDDOOR;      
  240.                 arg = rnd(30);        
  241.                 break;
  242.             case '~':     
  243.                 if (k!=MAXLEVEL-1) break;
  244.                 it = OLARNEYE;
  245.                 mit = DEMONPRINCE;
  246.                 marg = monster[mit].hitpoints;
  247.                 break;
  248.             case '!':     
  249.                 if (k!=MAXLEVEL+MAXVLEVEL-1)  
  250.                     break;
  251.                 it = OPOTION;    
  252.                 arg = 21;
  253.                 mit = LUCIFER;
  254.                 marg = monster[mit].hitpoints;
  255.                 break;
  256.             case '.':     
  257.                 if (k<MAXLEVEL)  break;
  258.                 mit = makemonst(k+1);
  259.                 marg = monster[mit].hitpoints;
  260.                 break;
  261.             case '-':     
  262.                 it = newobject(k+1,&arg);
  263.                 break;
  264.             };
  265.             item[j][i] = it;        
  266.             iarg[j][i] = arg;
  267.             mitem[j][i] = mit;
  268.             hitp[j][i] = marg;
  269. #if WIZID
  270.             know[j][i] = (wizard) ? 1 : 0;
  271. #else
  272.             know[j][i] = 0;
  273. #endif
  274.         }
  275.     }
  276.     lrclose();
  277.     return(1);
  278. }
  279.  
  280. /*
  281.     function to make a treasure room on a level
  282.     level 10's treasure room has the eye in it and demon lords
  283.     level V3 has potion of cure dianthroritis and demon prince
  284.  */
  285. treasureroom(lv)
  286. register int lv;
  287. {
  288.     register int tx,ty,xsize,ysize;
  289.  
  290.     for (tx=1+rnd(10);  tx<MAXX-10;  tx+=10)
  291.         if ( (lv==MAXLEVEL-1) || (lv==MAXLEVEL+MAXVLEVEL-1) || rnd(13)==2) {
  292.             xsize = rnd(6)+3;          
  293.             ysize = rnd(3)+3;  
  294.             ty = rnd(MAXY-9)+1;  /* upper left corner of room */
  295.             if (lv==MAXLEVEL-1 || lv==MAXLEVEL+MAXVLEVEL-1)
  296.                troom(lv,xsize,ysize,tx=tx+rnd(MAXX-24),ty,rnd(3)+6);
  297.             else 
  298.                 troom(lv,xsize,ysize,tx,ty,rnd(9));
  299.         }
  300. }
  301.  
  302. /*
  303.  *    subroutine to create a treasure room of any size at a given location 
  304.  *    room is filled with objects and monsters 
  305.  *    the coordinate given is that of the upper left corner of the room
  306.  */
  307. troom(lv,xsize,ysize,tx,ty,glyph)
  308. int lv,xsize,ysize,tx,ty,glyph;
  309. {
  310.     register int i,j;
  311.     int tp1,tp2;
  312.  
  313.     for (j=ty-1; j<=ty+ysize; j++)
  314.         for (i=tx-1; i<=tx+xsize; i++)    /* clear out space for room */
  315.             item[i][j]=0;
  316.     for (j=ty; j<ty+ysize; j++)
  317.         for (i=tx; i<tx+xsize; i++)    /* now put in the walls */
  318.         {     
  319.             item[i][j]=OWALL; 
  320.             mitem[i][j]=0; 
  321.         }
  322.     for (j=ty+1; j<ty+ysize-1; j++)
  323.         for (i=tx+1; i<tx+xsize-1; i++)    /* now clear out interior */
  324.             item[i][j]=0;
  325.     switch(rnd(2))        /* locate the door on the treasure room */
  326.     {
  327.     case 1:        
  328.         item[i=tx+rund(xsize)][j=ty+(ysize-1)*rund(2)]=OCLOSEDDOOR;
  329.         iarg[i][j] = glyph;  /* on horizontal walls */
  330.         break;
  331.     case 2: 
  332.         item[i=tx+(xsize-1)*rund(2)][j=ty+rund(ysize)]=OCLOSEDDOOR;
  333.         iarg[i][j] = glyph;    /* on vertical walls */
  334.         break;
  335.     };
  336.  
  337.     tp1=playerx;  
  338.     tp2=playery;  
  339.     playery=ty+(ysize>>1);
  340.     if (c[HARDGAME]<2)
  341.         for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2)
  342.             for (i=0, j=rnd(6); i<=j; i++) {     
  343.                 something(lv+2); 
  344.                 createmonster(makemonst(lv+2)); 
  345.             }
  346.     else
  347.         for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2)
  348.             for (i=0, j=rnd(4); i<=j; i++) {     
  349.                 something(lv+2); 
  350.                 createmonster(makemonst(lv+4)); 
  351.             }
  352.     playerx=tp1;
  353.     playery=tp2;
  354. }
  355.  
  356. /*
  357.     ***********
  358.     MAKE_OBJECT
  359.     ***********
  360.     subroutine to create the objects in the maze for the given level
  361.  */
  362. makeobject(j)
  363. register int j;
  364. {
  365.     register int i;
  366.  
  367.     if (j==0) {
  368.         fillroom(OENTRANCE,0);    /*    entrance to dungeon*/
  369.         fillroom(ODNDSTORE,0);    /*    the DND STORE    */
  370.         fillroom(OSCHOOL,0);    /*    college of Larn    */
  371.         fillroom(OBANK,0);    /*    1st national bank of larn*/
  372.         fillroom(OVOLDOWN,0);    /*    volcano shaft to temple*/
  373.         fillroom(OHOME,0);    /*    the players home & family*/
  374.         fillroom(OTRADEPOST,0);    /*      the trading post    */
  375.         fillroom(OLRS,0);    /*      the larn revenue service */
  376.         return;
  377.     }
  378.     if (j==MAXLEVEL) 
  379.         fillroom(OVOLUP,0); /* volcano shaft up from the temple */
  380.  
  381.     /*    make the fixed object in the maze STAIRS and 
  382.         random object ELEVATORS */
  383.  
  384.     if ((j>0) && (j != MAXLEVEL-1) && (j < MAXLEVEL+MAXVLEVEL-3)) 
  385.         fillroom(OSTAIRSDOWN,0);
  386.  
  387.     if ((j > 1) && (j != MAXLEVEL))    
  388.         fillroom(OSTAIRSUP,0);
  389.  
  390.     if ((j>3) && (j != MAXLEVEL))
  391.         if (c[ELVUP]==0)
  392.             if (rnd(100) > 85) {
  393.                 fillroom(OELEVATORUP,0);
  394.                 c[ELVUP]++;
  395.             }
  396.  
  397.     if ((j>0) && (j<=MAXLEVEL-2))
  398.         if (c[ELVDOWN]==0)
  399.             if (rnd(100) > 85) {
  400.                 fillroom(OELEVATORDOWN,0);
  401.                 c[ELVDOWN]++;
  402.             }
  403.  
  404.     /*    make the random objects in the maze        */
  405.     fillmroom(rund(3),OBOOK,j);                
  406.     fillmroom(rund(3),OCOOKIE,0);
  407.     fillmroom(rund(3),OALTAR,0);
  408.     fillmroom(rund(3),OSTATUE,0);
  409.     fillmroom(rund(3),OFOUNTAIN,0);            
  410.     fillmroom(rund(2),OTHRONE,0);            
  411.     fillmroom(rund(2),OMIRROR,0);
  412.  
  413.     if (j >= MAXLEVEL+MAXVLEVEL-3)
  414.         fillroom(OPIT,0);
  415.     fillmroom(rund(3),OPIT,0);
  416.  
  417.     if (j >= MAXLEVEL+MAXVLEVEL-3)
  418.         fillroom(OIVTRAPDOOR,0);
  419.     fillmroom(rund(2),OIVTRAPDOOR,0);
  420.     fillmroom(rund(2),OTRAPARROWIV,0);        
  421.     fillmroom(rnd(3)-2,OIVTELETRAP,0);
  422.     fillmroom(rnd(3)-2,OIVDARTRAP,0);
  423.  
  424.     if (j==1) fillmroom(1,OCHEST,j);
  425.     else       fillmroom(rund(2),OCHEST,j);
  426.  
  427.     if (j<MAXLEVEL-1) {
  428.         fillmroom(rund(2),ODIAMOND,rnd(10*j+1)+10);
  429.         fillmroom(rund(2),ORUBY,rnd(6*j+1)+6);
  430.         fillmroom(rund(2),OEMERALD,rnd(4*j+1)+4);
  431.         fillmroom(rund(2),OSAPPHIRE,rnd(3*j+1)+2);
  432.     }
  433.  
  434.     for (i=0; i<rnd(4)+3; i++)
  435.         fillroom(OPOTION,newpotion());    /*    make a POTION    */
  436.  
  437.     for (i=0; i<rnd(5)+3; i++)
  438.         fillroom(OSCROLL,newscroll());    /*    make a SCROLL    */
  439.  
  440.     for (i=0; i<rnd(12)+11; i++)
  441.         fillroom(OGOLDPILE,12*rnd(j+1)+(j<<3)+10); /* make GOLD    */
  442.  
  443.     if (j==8)    
  444.         fillroom(OBANK2,0);    /*    branch office of the bank */
  445.  
  446.     if ( (c[PAD]==0) &&  (j>=4) ) 
  447.         if (rnd(100) > 75) {
  448.             fillroom(OPAD,0);    /* Dealer McDope's Pad */
  449.             c[PAD]++;
  450.         }
  451.  
  452.     froom(2,ORING,0);        /* a ring mail     */
  453.     froom(1,OSTUDLEATHER,0);    /* a studded leather    */
  454.     froom(3,OSPLINT,0);        /* a splint mail*/
  455.     froom(5,OSHIELD,rund(3));    /* a shield    */
  456.     froom(2,OBATTLEAXE,rund(3));    /* a battle axe    */
  457.     froom(5,OLONGSWORD,rund(3));    /* a long sword    */
  458.     froom(5,OFLAIL,rund(3));    /* a flail    */
  459.     froom(7,OSPEAR,rnd(5));        /* a spear    */
  460.     froom(4,OREGENRING,rund(3));    /* ring of regeneration */
  461.     froom(1,OPROTRING,rund(3));    /* ring of protection    */
  462.     froom(2,OSTRRING,rund(5));     /* ring of strength  */
  463.     froom(2,ORINGOFEXTRA,0);    /* ring of extra regen    */
  464.  
  465.     if (c[LAMP]==0) {
  466.         if (rnd(120) < 8) {
  467.             fillroom (OBRASSLAMP,0);
  468.             c[LAMP]++;
  469.             goto zug;
  470.         }
  471.     }
  472.  
  473.     if (c[WAND]==0) {    /* wand of wonder */
  474.         if (rnd(120) < 8) {
  475.             fillroom(OWWAND,0);
  476.             c[WAND]++;
  477.             goto zug;
  478.         }
  479.     }
  480.  
  481.     if (c[DRAGSLAY]==0) /* orb of dragon slaying */
  482.         if(rnd(120) < 8) {
  483.             fillroom(OORBOFDRAGON,0);
  484.             c[DRAGSLAY]++;
  485.             goto zug;
  486.         }
  487.  
  488.     if (c[NEGATE]==0)    /* scarab of negate spirit */
  489.         if(rnd(120) < 8) {
  490.             fillroom(OSPIRITSCARAB,0);
  491.             c[NEGATE]++;
  492.             goto zug;
  493.         }
  494.  
  495.     if (c[CUBEUNDEAD]==0)        /* cube of undead control */
  496.         if (rnd(120) < 8) {
  497.             fillroom(OCUBEofUNDEAD,0);    
  498.             c[CUBEUNDEAD]++;
  499.             goto zug;
  500.         }
  501.  
  502.     if (c[DEVICE]==0)    /* device of antitheft */
  503.         if (rnd(120) < 8) {
  504.             fillroom(ONOTHEFT,0);        
  505.             c[DEVICE]++;
  506.             goto zug;
  507.         }
  508.  
  509.     if(c[TALISMAN]==0)         /* talisman of the sphere */
  510.         if(rnd(120) < 8) {
  511.             fillroom(OSPHTALISMAN,0);
  512.             c[TALISMAN]++;
  513.             goto zug;
  514.         }
  515.  
  516.     if (c[HAND]==0)        /* hand of fear */
  517.         if (rnd(120) < 8) {
  518.             fillroom(OHANDofFEAR,0);    
  519.             c[HAND]++;
  520.             goto zug;
  521.         }
  522.  
  523.     if (c[ORB] == 0)     /* orb of enlightenment */
  524.         if (rnd(120) < 8) {
  525.             fillroom(OORB,0);
  526.             c[ORB]++;
  527.             goto zug;
  528.         }
  529.  
  530.     if (c[ELVEN]==0)    /* elven chain */
  531.         if (rnd(120) < 8) {
  532.             fillroom(OELVENCHAIN,0);
  533.             c[ELVEN]++;
  534.         }
  535. zug:
  536.     if (c[SLASH]==0)    /* sword of slashing */
  537.         if (rnd(120) < 8) {
  538.             fillroom(OSWORDofSLASHING,0);     
  539.             c[SLASH]++;
  540.         }
  541.  
  542.     if (c[BESSMANN]==0)    /* Bessman's flailing hammer */ 
  543.     if(rnd(120) < 8) {
  544.         fillroom(OHAMMER,0);    
  545.         c[BESSMANN]++;
  546.     }
  547.  
  548.     if ((j>=10)&&(j<=20)&&(c[SLAY]==0))    /* Slayer */
  549.         if (rnd(100) > 85-(j-10)) {
  550.             fillroom (OSLAYER,0);
  551.             c[SLAY]++;
  552.         }
  553.  
  554.     if ((c[STAFF]==0) && (j>=8) && (j<=20))    /* staff of power */
  555.         if (rnd(100) > 85-(j-10)) {
  556.             fillroom(OPSTAFF,0);
  557.             c[STAFF]++;
  558.         }
  559.  
  560.     if (c[HARDGAME]<3 || (rnd(4)==3)) {     
  561.         if (j>3) {     
  562.             froom(3,OSWORD,rund(6));  /* sunsword */
  563.             froom(5,O2SWORD,rnd(6));  /* a two handed sword    */
  564.             froom(3,OBELT,rund(7));      /* belt of striking    */
  565.             froom(3,OENERGYRING,rund(6));    /* energy ring    */
  566.             froom(4,OPLATE,rund(8));  /* platemail */
  567.         }
  568.     }
  569. }
  570.  
  571. /*
  572.     subroutine to fill in a number of objects of the same kind
  573.  */
  574. fillmroom(n,what,arg)
  575. int n,arg;
  576. char what;
  577. {
  578.     register int i;
  579.  
  580.     for (i=0; i<n; i++)        
  581.         fillroom(what,arg);
  582. }
  583.  
  584. froom(n,itm,arg)
  585. int n;
  586. char itm;
  587. int arg;
  588. {    
  589.     if (rnd(151) < n) 
  590.         fillroom(itm,arg);    
  591. }
  592.  
  593. /*
  594.  *    subroutine to put an object into an empty room
  595.  *    uses a random walk
  596.  */
  597. fillroom(what,arg)
  598. char what;
  599. int arg;
  600. {
  601.     register int x,y;
  602.  
  603.     x=rnd(MAXX-2);  
  604.     y=rnd(MAXY-2);
  605.     while (item[x][y]) {
  606.         x += rnd(3)-2;        
  607.         y += rnd(3)-2;
  608.         if (x > MAXX-2)  x=1;        
  609.         if (x < 1)  x=MAXX-2;
  610.         if (y > MAXY-2)  y=1;        
  611.         if (y < 1)  y=MAXY-2;
  612.     }
  613.     item[x][y]=what;        
  614.     iarg[x][y]=arg;
  615. }
  616.  
  617. /*
  618.     subroutine to put monsters into an empty room without walls or other
  619.     monsters
  620.  */
  621. fillmonst(what)
  622. char what;
  623. {
  624.     register int x,y,trys;
  625.  
  626.     for (trys=10; trys>0; --trys) /* max # of creation attempts */
  627.     {
  628.         x=rnd(MAXX-2);  
  629.         y=rnd(MAXY-2);
  630.         if ((item[x][y]==0) && (mitem[x][y]==0) && 
  631.                     ((playerx!=x) || (playery!=y))) {
  632.             mitem[x][y] = what;  
  633.             know[x][y]=0;
  634.             hitp[x][y] = monster[what].hitpoints;  
  635.             return(0);
  636.         }
  637.     }
  638.     return(-1); /* creation failure */
  639. }
  640.  
  641. /*
  642.     creates an entire set of monsters for a level
  643.     must be done when entering a new level
  644.     if sethp(1) then wipe out old monsters else leave them there
  645.  */
  646. sethp(flg)
  647. int flg;
  648. {
  649.     register int i,j;
  650.  
  651.     if (flg) 
  652.         for (i=0; i<MAXY; i++) 
  653.             for (j=0; j<MAXX; j++) 
  654.                 stealth[j][i]=0;
  655.     if (level==0) {     
  656.         c[TELEFLAG]=0; 
  657.         return; 
  658.     } /*    if teleported and found level 1 then know level we are on */
  659.  
  660.     if (flg)  
  661.         j = rnd(12) + 2 + (level>>1);   
  662.     else   
  663.         j = (level>>1) + 1;
  664.  
  665.     for (i=0; i<j; i++)  
  666.         fillmonst(makemonst(level));
  667.  
  668.     if ((level >= 11) && (level<=15)) {
  669.         i=level-10;
  670.         for (j=1;j<=i;j++)
  671.             if (fillmonst(DEMONLORD+rund(7))==-1)
  672.                 j--;
  673.     }
  674.     if (level > 15 ) {
  675.         i=level-15;
  676.         for (j=1;j<=i;j++)
  677.             if (fillmonst(DEMONPRINCE)==-1)
  678.                 j--;
  679.     }
  680.     positionplayer();
  681. }
  682.  
  683. /*
  684.  *    Function to destroy all genocided monsters on the present level
  685.  */
  686. checkgen()
  687. {
  688.     register int x,y;
  689.  
  690.     for (y=0; y<MAXY; y++)
  691.         for (x=0; x<MAXX; x++)
  692.             if (monster[mitem[x][y]].genocided)
  693.                 mitem[x][y]=0; /* no more monster */
  694. }
  695.